package com.itheima.reggie.controller;

import com.itheima.reggie.comon.OssTemplate;
import com.itheima.reggie.comon.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Objects;

@RestController
public class FileController {
    //文件上传
    @Autowired
    private OssTemplate ossTemplate;

    @PostMapping("/common/upload")
    public ResultInfo<Object> fileUpload(@RequestBody MultipartFile file) throws IOException {
        String newFile = ossTemplate.upload(Objects.requireNonNull(file.getOriginalFilename()), file.getInputStream());
        return ResultInfo.success(newFile);
    }
}
